<template>
	<view class="container">
		<u-list @scrolltolower="scrolltolower">
			<u-list-item v-for="(item, index) in indexList" :key="index" style="position: relative;">
				<u-cell :title="item.username?item.username:'找不到了~'">
					<u-avatar slot="icon" shape="square" size="35" :src="item.active"
						customStyle="margin: -3px 5px -3px 0"></u-avatar>
				</u-cell>
				<view class="content">
					{{item.content}}
				</view>
				<view class="del_view" @click="del_shuoshuo(item)">
					删除
				</view>
			</u-list-item>
		</u-list>

		<view class="add_float" @click="add_li">
			+
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				indexList: []
			}
		},
		onPullDownRefresh() {
			this.get_list()
			uni.stopPullDownRefresh()
		},
		mounted() {
			console.log(this.$store.state.users._id)
			this.get_list()
		},
		methods: {
			del_shuoshuo(item){
				var that=this
				uni.showModal({
					title: '警告!',
					content: '您正在清除此数据!',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							const db = uniCloud.database();
							// db.collection('user-list').doc(id).remove();
						  db.collection('shuoshuo_list').where({
							 _id:item._id,
							 user_id:that.$store.state.users._id
							}).remove().then(res=>{
								that.get_list()
							})
							
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
				
			},
			get_list() {
				uniCloud.callFunction({
					name:'get_myshuoshuo',
					data:{
						_id:this.$store.state.user._id
					}
				}).then(res=>{
					console.log(res)
					if (res.errCode == 0) {
						this.indexList = res.result.data
					} else {
						uni.showToast({
							title: '网络错误~',
							icon: 'none'
						})
					}
				})
			},
			scrolltolower() {
				this.loadmore()
			},
			add_li() {
				uni.navigateTo({
					url: '/page_shuoshuo/add_shuoshuo/add_shuoshuo'
				})
			},
		}
	}
</script>

<style scoped>
	
	.container{
		height: calc(100vh - 200rpx);

	}
	.add_float {
		width: 100rpx;
		height: 100rpx;
		background: #ff8272;
		color: #fff;
		font-size: 50rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		position: fixed;
		bottom: 200rpx;
		right: 50rpx;
		border-radius: 100rpx;
	} 
	::v-deep .u-list{
		width:95%;
		margin: 0 auto;
	}

	::v-deep .u-list .u-list-item{
		border: 1px solid #ccc;
		border-radius: 10rpx;
		margin-top: 15rpx;
		position: relative;
	}
	.del_view{
		width: fit-content;
		padding: 10rpx;
		border: 1px solid #ff8272;
		border-radius: 10rpx;
		position: absolute;
		top: 10rpx;
		right: 20rpx;
		font-size:24rpx;
		color: #333;
	}
	
	.content{
		padding:20rpx;
		box-sizing: border-box;
		font-size:28rpx;
	}
</style>